package com.appspot.finajjarane.web.mvc.controllers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.appspot.finajjarane.framework.generic.ApplicationConstants;
import com.appspot.finajjarane.framework.generic.Utils;
import com.appspot.finajjarane.framework.models.ArticleModel;
import com.appspot.finajjarane.framework.service.IArticleService;

@Controller
public class Home {

	@Autowired
	private IArticleService articleService;


	@RequestMapping("/")
	public ModelAndView about(){

		Map<String, Object> data = new HashMap<String, Object>();
		List<ArticleModel> articles;

		try {
			articles = articleService.getArticlesList(1, ApplicationConstants.NBR_ARTICLES_PER_PAGE_FRONT_HOME, Utils.getLanguage());
			data.put("articles",articles);
		} catch (Exception e) {
			data.put("articles",null);
		}


		data.put("menuItem", "home");
		data.put("lang", Utils.getLanguage());

		return new ModelAndView("home",data);

	}
}